<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      // 变量作用域
      // 函数对象
      // 闭包
      function makeCounter() {
        // const counter = {};
        const counter = function () {};
        counter.count = 0;
        counter.set = function (v) {
          this.count = v;
        };
        counter.decrease = function (v) {
          this.count -= v;
        };
        return counter;
      }
      const c = makeCounter();
      c.set(100);
      console.log(counter.count); //100
      c.decrease(20);
      console.log(counter.count); //80
    </script>
  </body>
</html>
